home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DIRS.SWG / 0002_Long File Names.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  7.7 KB  |  284 lines

  1. {
  2. Okay everyone, a temporary kludge.. it works at least.  I'll try releasing a
  3. full Windows 95 unit later on which will replace all the DOS functions with
  4. new ones or something along those lines.  I ended up buying _Programmer's
  5. Guide to Microsoft Windows 95_ from Microsoft Press.
  6. *** D:\BP\WORK\LFN.PAS }
  7.  
  8. program LFNDir;
  9. {$N+}
  10.  
  11. {si=1 instead of 0 gives a normal DOS date/time instead of the 100ns
  12. stuff}
  13.  
  14. uses DOS, Strings;
  15.  
  16. const
  17.  
  18. { File attribute constants }
  19.  
  20.   ReadOnly  = $0001;
  21.   Hidden    = $0002;
  22.   SysFile   = $0004;
  23.   VolumeID  = $0008;
  24.   Directory = $0010;
  25.   Archive   = $0020;
  26.   AnyFile   = $003F;
  27.   TempFile  = $0100;
  28.  
  29. var
  30.  
  31. { Error status variable }
  32.  
  33. LFNError: word;
  34.  
  35. type
  36.  
  37.   FindData = record
  38. Attributes: longint;
  39.   CreationTime,
  40.   LastAccessTime,
  41.   ModificationTime: comp;  {<- old MS-DOS one}
  42.   FileSizeHigh,
  43.   FileSizeLow: longint;
  44.   Reserved: array[1..8] of byte;
  45.   LongFileName: array[1..260] of char;
  46.   FileName: array[1..14] of char;
  47.   End;
  48.  
  49. function ASCIZToString (ASCIZ: array of Char): String;
  50. begin
  51. ASCIZToString := StrPas (@ASCIZ);
  52. end;
  53.  
  54. function FindFirst (Path: String; Attr: word; var F: FindData): word;
  55. assembler;
  56. asm
  57.   mov     LFNError, 0
  58.  
  59. push    ds
  60.   lds     si, Path
  61.   mov     dx, si
  62.   inc     dx
  63.   mov     cl, [si]
  64.  
  65. @@StringToPChar:
  66.   inc     si
  67.   dec     cl
  68.   jnz     @@StringToPChar
  69.  
  70.   inc     si
  71.   mov     byte ptr [si], 0
  72.  
  73.   les     di, F
  74.  
  75.   mov     cx, Attr
  76.   mov     ax, 714Eh
  77.   mov     si, 1
  78.  
  79.   int     21h                          ;{CF set on error}
  80.   pop     ds
  81.   jnc     @@NoCarry
  82.  
  83.   mov     LFNError, ax
  84.   jmp     @@Exit
  85.  
  86. @@NoCarry:
  87. cmp     ax, 7100h
  88.   jne     @@Exit
  89.  
  90.   mov     LFNError, ax
  91.  
  92. @@Exit:
  93. end;
  94.  
  95. procedure FindNext (var F: FindData; FileFindHandle: word); assembler;
  96. asm
  97.   mov     LFNError, 0
  98.  
  99.   mov     ax, 714Fh
  100.   mov     si, 1
  101.   mov     bx, FileFindHandle
  102.   les     di, F
  103.  
  104.   int     21h
  105.  
  106.   jnc     @@NoCarry
  107.  
  108.   mov     LFNError, ax
  109.   jmp     @@Exit
  110.  
  111. @@NoCarry:
  112. cmp     ax, 7100h
  113.   jne     @@Exit
  114.  
  115.   mov     LFNError, ax
  116.  
  117. @@Exit:
  118. end;
  119.  
  120. procedure FindClose (FileFindHandle: word); assembler;
  121. asm
  122.   mov     LFNError, 0
  123.  
  124.   mov     ax, 71A1h
  125.   mov     bx, FileFindHandle
  126.  
  127.   int     21h
  128.  
  129.   jnc     @@NoCarry
  130.  
  131.   mov     LFNError, ax
  132.   jmp     @@Exit
  133.  
  134. @@NoCarry:
  135. cmp     ax, 7100h
  136.   jne     @@Exit
  137.  
  138.   mov     LFNError, ax
  139.  
  140. @@Exit:
  141. end;
  142.  
  143. const
  144. nshpers: longint = 1000000000 div 100;
  145. sixty:word=60;
  146.   thirtysixhundred:word=3600;
  147.   hoursconst:longint=86400;
  148.  
  149. {procedure extime (time:comp;var dt:DateTime); assembler;
  150. asm
  151.   les     di, dt
  152.   add     di, OFFSET DateTime. Minute
  153.   mov     ax, es:[di]
  154. end;}
  155. (*
  156. procedure expandtime (time: comp; var dt:DateTime);
  157. assembler;
  158. {
  159. time = number of 100 nanosecond intervals since midnight, 1st January, 1601
  160. yes, 1601.
  161. second = (time / 10000000) mod 60
  162. minute = ((time / 10000000) mod 3600) div 60
  163.  
  164. }
  165. var
  166. Dummy: Word;
  167.  
  168. asm
  169.  
  170. ;{
  171. COMMENT ENDCOMMENT
  172.   blah
  173.   blah
  174. ENDCOMMENT
  175. ;}
  176.  
  177.   les     di, dt
  178.   add     di, OFFSET DateTime. Sec
  179.  
  180.   ;{find seconds}
  181.   finit                                ;{clear the stack for me!}
  182.   fild    time                         ;{load the time into ST(0)}
  183.   fidiv   nshpers                      ;{get the number of seconds since..}
  184.   fst     ST(1)                        ;{save a copy for later..}
  185.   fild    sixty                        ;{ST(0) := 60; (time -> ST(1))}
  186.   fxch                                 ;{swap ST(1) and (0)}
  187.   fprem                                ;{ST(0) := ST(0) mod ST(1);}
  188.   fistp   word ptr es:[di]             ;{dt. sec := ST(0)}
  189.   sub     di, 2                        ;{es:[di] points to dt. min}
  190.  
  191.   ;{find minutes}
  192.   fistp   Dummy                        ;{get rid of ST(0) (60)}
  193.   fst     ST(2)                        ;{save a copy of new time for later..}
  194.   fild    thirtysixhundred             ;{ST(0) := 3600; (time -> ST(1))}
  195.   fxch                                 ;{exchange ST0/1}
  196.   fprem                                ;{ST(0) := ST(0) mod ST(1);}
  197.   fxch                                 ;{exchange ST0/1}
  198.   fistp   Dummy                        ;{get rid of ST(0) (3600)}
  199.   fidiv   sixty                        ;{ST(0) := ST(0) / ST(1) (60)}
  200.   fst     ST(1)                        ;{make a copy of minutes for later..}
  201.   frndint                              ;{round off ST(1) to nearest int.}
  202.   fcom                                 ;{compare rounded & unrounded}
  203.   fstsw   ax                           ;{store FPU status to ax}
  204.   sahf                                 ;{store ah to CPU status}
  205. { jp      Error}                       ;{C2 (->parity) set on compare error}
  206.   jc      @@NotGreater                 ;{C0 (->carry) set on less or error}
  207.   jz      @@NotGreater                 ;{C3 (->zero) set on equal or error}
  208.                                        ;{correct for rounding up! (no trunc)}
  209.   fld1                                 ;{ST(0) := 1 (round (minutes) -> ST(1))
  210.   fsub                                 ;{ST(0) := ST(0) - ST(1) (minutes-1)}
  211. @@NotGreater:                          ;{minutes was rounded down, or cont.}
  212.   fistp   word ptr es:[di]             ;{dt. min := ST(0)}
  213.   sub     di, 2                        ;{es:[di] points to dt. hour}
  214.  
  215.   ;{find hours}
  216.   fistp   Dummy                        ;{get rid of ST(0) (60)}
  217.   fst     ST(2)                        ;{save a copy of new time for later..}
  218.   fild    hoursconst                   ;{ST(0) := 3600*24; (time -> ST(1))}
  219.   fxch                                 ;{exchange ST0/1}
  220.   fprem                                ;{ST(0) := ST(0) mod ST(1);}
  221.   fxch                                 ;{exchange ST0/1}
  222.   fistp   Dummy                        ;{get rid of ST(0) (3600)}
  223.   fidiv   thirtysixhundred             ;{ST(0) := ST(0) / ST(1) (3600)}
  224.   fst     ST(1)                        ;{make a copy of minutes for later..}
  225.   frndint                              ;{round off ST(1) to nearest int.}
  226.   fcom                                 ;{compare rounded & unrounded}
  227.   fstsw   ax                           ;{store FPU status to ax}
  228.   sahf                                 ;{store ah to CPU status}
  229. { jp      Error}                       ;{C2 (->parity) set on compare error}
  230.   jc      @@NotGreater2                ;{C0 (->carry) set on less or error}
  231.   jz      @@NotGreater2                ;{C3 (->zero) set on equal or error}
  232.                                        ;{correct for rounding up! (no trunc)}
  233.   fld1                                 ;{ST(0) := 1 (round (minutes) -> ST(1))
  234.   fsub                                 ;{ST(0) := ST(0) - ST(1) (minutes-1)}
  235. @@NotGreater2:                         ;{minutes was rounded down, or cont.}
  236.   fistp   word ptr es:[di]             ;{dt. min := ST(0)}
  237.   sub     di, 2                        ;{es:[di] points to dt. hour}
  238.  
  239. end;
  240.  
  241.  
  242. {  fxchg
  243.   fild    nshpers
  244.  
  245.   fdiv}
  246.  
  247. {begin
  248.   time := trunc (time / (1000*1000*1000/100));
  249.   second := time mod 60;
  250.   minute := time mod (60*60) div 60;
  251.   hour := time mod (60*60*60) div (60*60);
  252. end;}
  253. *)
  254. function long (c: comp):word; assembler;
  255. asm
  256. mov dx, word ptr c[2]
  257.   mov ax, word ptr c[0]
  258. end;
  259.  
  260. var
  261. Find: FindData;
  262.   FileFindHandle: Word;
  263.   dt: DateTime;
  264.  
  265. begin
  266.   { change this to suit your drive !! }
  267.   FileFindHandle := FindFirst ('d:\PROGRAM FILES\*.*', 255, Find);
  268.  
  269.   repeat
  270.   If Not (LFNError = 0) Then begin
  271.       halt;
  272.     end;
  273.     unpacktime (long (find. modificationtime), dt);
  274.     {expandtime (find. modificationtime, dt);}
  275.  
  276.   WriteLn (ASCIZToString (Find. FileName),
  277. ASCIZToString (Find. LongFileName), dt. hour, ':', dt. min, ':', dt. sec);
  278. {    writeln (x);}
  279.     FindNext (Find, FileFindHandle);
  280.   Until (LFNError <> 0);
  281.  
  282.   FindClose (FileFindHandle);
  283. End.
  284.